package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsCostAdjustmentDto;
import com.sale.goods.domain.dto.GoodsCostAdjustmentViewDto;
import com.sale.goods.domain.vo.ExamineVo;
import com.sale.goods.domain.vo.GoodsCostAdjustmentAddVo;
import com.sale.goods.domain.vo.GoodsCostAdjustmentVo;
import com.sale.goods.service.GoodsCostAdjustmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 成本调整控制层
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cost-adjustment")
public class GoodsCostAdjustmentController extends BaseController {

    private final GoodsCostAdjustmentService goodsCostAdjustmentService;


    /**
     * 成本调整分页列表
     */
    //@SaCheckPermission("finance:adjustment:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsCostAdjustmentDto> costAdjustmentList(GoodsCostAdjustmentVo goodsCostAdjustmentVo, PageQuery pageQuery) {
        return goodsCostAdjustmentService.getCostAdjustmentList(goodsCostAdjustmentVo, pageQuery);
    }

    /**
     * 成本调整新增
     */
    //@SaCheckPermission("finance:adjustment:add")
    @Log(title = "成本调整新增", businessType = BusinessType.INSERT)
    @PostMapping("/costAdjustmentAdd")
    public R<Void> costAdjustmentAdd(@RequestBody GoodsCostAdjustmentAddVo goodsCostAdjustmentAddVo) {
        return toAjax(goodsCostAdjustmentService.costAdjustmentAdd(goodsCostAdjustmentAddVo));
    }

    /**
     * 成本调整修改
     */
    //@SaCheckPermission("finance:adjustment:edit")
    @Log(title = "成本调整修改", businessType = BusinessType.UPDATE)
    @PutMapping("/costAdjustmentUpdate")
    public R<Void> costAdjustmentUpdate(@RequestBody GoodsCostAdjustmentAddVo goodsCostAdjustmentAddVo) {
        return toAjax(goodsCostAdjustmentService.costAdjustmentUpdate(goodsCostAdjustmentAddVo));
    }

    /**
     * 成本调整查看
     */
    //@SaCheckPermission("finance:adjustment:query")
    @GetMapping("/getView/{id}")
    public R<GoodsCostAdjustmentViewDto> costAdjustmentGetView(@PathVariable("id") Long id) {
        return R.ok(goodsCostAdjustmentService.costAdjustmentGetView(id));
    }

    /**
     * 删除
     */
    //@SaCheckPermission("finance:adjustment:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteGoodsCostAdjustment/{id}")
    public R<Void> deleteGoodsCostAdjustment(@PathVariable("id") Long id) {
        return toAjax(goodsCostAdjustmentService.deleteGoodsCostAdjustment(id));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:adjustment:subExamine")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @GetMapping("/subReview/{id}")
    public R<Void> subReview(@PathVariable("id") Long id) {
        return toAjax(goodsCostAdjustmentService.subReview(id));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:adjustment:revoke")
    @Log(title = "撤销审核", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{id}")
    public R<Void> deleteReview(@PathVariable("id") Long id) {
        return toAjax(goodsCostAdjustmentService.deleteReview(id));
    }

    /**
     * 审核
     */
    //@SaCheckPermission("finance:adjustment:examine")
    @Log(title = "成本调整审核", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@RequestBody ExamineVo examineVo) throws Exception {
        return toAjax(goodsCostAdjustmentService.examine(examineVo));
    }

}
